function ImageModal(element) {
    if (!element) return;

    const imageUrl = element.src;
    let modal = document.createElement('div');
    modal.style.display = 'none';
    modal.style.position = 'fixed';
    modal.style.top = '0';
    modal.style.left = '0';
    modal.style.right = '0';
    modal.style.bottom = '0';
    modal.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
    modal.style.justifyContent = 'center';
    modal.style.alignItems = 'center';
    modal.style.zIndex = '1000';

    const modalImage = document.createElement('img');
    modalImage.src = imageUrl;
    modalImage.style.maxWidth = '90%';
    modalImage.style.maxHeight = '90%';

    modal.appendChild(modalImage);
    document.body.appendChild(modal);

    let timer;
    let isHovering = false; // 用于追踪鼠标是否仍然在图片上

    element.addEventListener('mouseenter', () => {
        isHovering = true;
        timer = setTimeout(() => {
            if (isHovering) { // 确保鼠标仍然在图片上
                modal.style.display = 'flex';
            }
        }, 1000);
    });

    element.addEventListener('mouseleave', () => {
        isHovering = false; // 鼠标移出
        clearTimeout(timer);
        setTimeout(() => {
            if (!isHovering) { // 只有鼠标真的离开，才隐藏 `modal`
                modal.style.display = 'none';
            }
        }, 200);
    });

    modal.addEventListener('mouseenter', () => {
        isHovering = true; // 鼠标进入模态框
        clearTimeout(timer);
    });

    modal.addEventListener('mouseleave', () => {
        isHovering = false; // 鼠标移出模态框
        setTimeout(() => {
            if (!isHovering) {
                modal.style.display = 'none';
            }
        }, 200);
    });

    // 点击模态框外部关闭
    modal.addEventListener('click', (e) => {
        if (e.target === modal) {
            modal.style.display = 'none';
        }
    });
}


function ImageUpload(target, callback) {
    let element = typeof target === 'string' ? document.getElementById(target) : target;
    if (!element) return;

    element.addEventListener('click', () => {
        let input = document.createElement('input');
        input.type = 'file';
        input.accept = 'image/*';
        input.style.display = 'none';

        input.addEventListener('change', () => {
            if (input.files.length === 0) return;

            let file = input.files[0];
            if (callback && typeof callback === 'function') {
                callback(file)
            }
        });
        input.click();
    });
}